//
// REGIONS
// Regions represent contiguous chunks of text in a CodeBox.
//
// This should logically be local to CodeBox, but the silly C# compiler won't let
// you store it in a separate file then.
//

using System;

namespace Meta.Editor {
	public struct Region {
		public int start;
		public int length;

		public int Start {
			get {
				return start;
			}
			set {
				start = value;
			}
		}

		public int End {
			get {
				return start+length;
			}
			set {
				length = value-start;
			}
		}

		public bool Equals(Region r) {
			return this.start==r.start && this.length==r.length;
		}

		public Region(int p, int l) {
			if (p<0) {
				start = 0;
				length = 0;
			} else if (l<0) {
				start = p-l;
				length = -l;
			} else {
				start = p;
				length = l;
			}
		}

		public override string ToString() {
			return "Region("+start.ToString()+", "+length.ToString()+")";
		}

	}
}
